<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" th:href="@{/res/css/amazeui.min.css}"/>
    <link rel="stylesheet" th:href="@{/res/css/admin.css}"/>
    <script th:src="@{/js/jquery-1.11.3.min.js}"></script>
    <script th:src="@{/myplugs/js/plugs.js}"></script>
</head>

<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">财务审核</strong>
            <small></small>
        </div>
    </div>

    <hr>

    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <!--                    <button type="button" class="am-btn am-btn-default"><span class="am-icon-plus" onclick="add()"></span> 新增</button>-->
                </div>
            </div>
        </div>
<!--        <div class="am-u-sm-12 am-u-md-3">-->

<!--        </div>-->
        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-input-group am-input-group-sm">
                <input type="text" class="am-form-field" id="search" placeholder="请输入要查找的账户名">
                <span class="am-input-group-btn"><button class="am-btn am-btn-default" type="button" onclick="search()">搜索</button></span>
            </div>
        </div>
    </div>

    <div class="am-g">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-id">序号</th>
                        <th class="table-type">账户名</th>
                        <th class="table-type">业务类型</th>
                        <th class="table-type">交易金额</th>
                        <th class="table-type">申请时间</th>
                        <th class="table-type">审核状态</th>
                        <th class="table-set">操作</th>
                    </tr>
                    </thead>

                    <tbody id="mytable"></tbody>
                </table>

                <div class="am-cf">
                    共<a><span id="listcount"></span></a>条记录
                    <div class="am-fr">
                        <ul class="am-pagination">
                            <!--<li class="am-disabled">
                                <a href="#">«</a>
                            </li>
                            <li class="am-active">
                                <a href="#">1</a>
                            </li>
                            <li>
                                <a href="#">2</a>
                            </li>
                            <li>
                                <a href="#">3</a>
                            </li>
                            <li>
                                <a href="#">»</a>
                            </li>-->
                        </ul>
                    </div>
                </div>
                <hr>
            </form>
        </div>
    </div>
</div>
</body>

<script>
    //保存查询的结果列表
    var list = "";

    $(function () {
        //表格
        var $tbody = $("#mytable");

        $.ajax({
            type: 'post',
            url: '/finance/getFinList',
            data: {},
            dataType: 'json',
            success: function (mydata) {
                list = mydata;
                var newHtml = '';
                $("#listcount").html(" " + mydata.length / 2 + " ");
                for (var i = 0, j = 0; i < mydata.length; i = i + 2, j++) {
                    newHtml += '<tr class="low-' + i + '">';
                    newHtml += '  <td>' + parseInt(j + 1) + '</td>';
                    newHtml += '  <td>' + mydata[i + 1].name + '</td>';
                    newHtml += '  <td>' + mydata[i].type + '</td>';
                    newHtml += '  <td>' + mydata[i].money + '</td>';
                    newHtml += '  <td>' + timeFormat(mydata[i].applyTime) + '</td>';
                    newHtml += '  <td>' + mydata[i].state + '</td>';
                    newHtml += '  <td>';
                    newHtml += '      <div class="am-btn-toolbar">';
                    newHtml += '          <div class="am-btn-group am-btn-group-xs">';
                    if (mydata[i].state.lastIndexOf("已") == -1) {
                        newHtml += '              <a href="#" class="am-btn am-btn-default" onclick="check(' + i + ')"><span class="am-icon-pencil-square-o"></span> 审核 </a>';
                    } else {
                        newHtml += '              <a href="javascript:return false;" class="am-btn am-btn-default am-disabled"><span class="am-icon-pencil-square-o"></span> 审核 </a>';
                    }
                    newHtml += '          </div>';
                    newHtml += '      </div>';
                    newHtml += '  </td>';
                    newHtml += '</tr>';
                }
                $tbody.html(newHtml);
            },
            error: function () {
                alert("error");
            }
        })
    });

    //json时间格式转换
    function timeFormat(time) {
        var d = new Date(time);

        var year = d.getFullYear();       //年
        var month = d.getMonth() + 1;     //月
        var day = d.getDate();            //日

        var hh = d.getHours();            //时
        var mm = d.getMinutes();          //分
        var ss = d.getSeconds();           //秒

        var clock = year + "/";

        if (month < 10)
            clock += "0";

        clock += month + "/";

        if (day < 10)
            clock += "0";

        clock += day + " ";

        if (hh < 10)
            clock += "0";

        clock += hh + ":";
        if (mm < 10) clock += '0';
        clock += mm + ":";

        if (ss < 10) clock += '0';
        clock += ss;
        return (clock);
    };

    //查找符合条件的记录
    function search() {
        //表格
        var $tbody = $("#mytable");

        //获取搜索条件
        var uName = document.getElementById("search").value;

        $.ajax({
            type: 'post',
            url: '/finance/selectByName',
            data: {name: uName},
            dataType: 'json',
            success: function (mydata) {
                list = mydata;
                var newHtml = '';
                $("#listcount").html(" " + mydata.length / 2 + " ");
                for (var i = 0, j = 0; i < mydata.length; i = i + 2, j++) {
                    newHtml += '<tr class="low-' + i + '">';
                    newHtml += '  <td>' + parseInt(j + 1) + '</td>';
                    newHtml += '  <td>' + mydata[i + 1].name + '</td>';
                    newHtml += '  <td>' + mydata[i].type + '</td>';
                    newHtml += '  <td>' + mydata[i].money + '</td>';
                    newHtml += '  <td>' + timeFormat(mydata[i].applyTime) + '</td>';
                    newHtml += '  <td>' + mydata[i].state + '</td>';
                    newHtml += '  <td>';
                    newHtml += '      <div class="am-btn-toolbar">';
                    newHtml += '          <div class="am-btn-group am-btn-group-xs">';
                    if (mydata[i].state.lastIndexOf("已") == -1) {
                        newHtml += '              <a href="#" class="am-btn am-btn-default" onclick="check(' + i + ')"><span class="am-icon-pencil-square-o"></span> 审核 </a>';
                    } else {
                        newHtml += '              <a href="javascript:return false;" class="am-btn am-btn-default am-disabled"><span class="am-icon-pencil-square-o"></span> 审核 </a>';
                    }
                    newHtml += '          </div>';
                    newHtml += '      </div>';
                    newHtml += '  </td>';
                    newHtml += '</tr>';
                }
                $tbody.html(newHtml);
            },
            error: function () {
                alert("error");
            }
        })
    }

    //审核
    function check(i) {
        var id = list[i].id;
        var uName = list[i + 1].name;
        var type = list[i].type;
        var money = list[i].money;
        var time = list[i].applyTime;
        var state = list[i].state;
        $.jq_Panel({
            title: "审核财务记录",
            iframeWidth: 500,
            iframeHeight: 300,
            url: "/checkFin?id=" + id + "&uName=" + uName + "&type=" + type + "&money=" + money + "&time=" + time + "&state=" + state
        });
    }
</script>
</html>